ARG FRAPPE_BRANCH=develop
FROM node:14-buster
ARG FRAPPE_BRANCH=develop

COPY install_frappe.sh /install_frappe
COPY install_erpnext.sh /install_erpnext
COPY install_app.sh /install_app
COPY prepare_production.sh /prepare_production

# Install frappe
RUN /install_frappe ${FRAPPE_BRANCH} && \
  # Install erpnext
  /install_erpnext && \
  # Install required apps with following command
  # /install_app <app_name> <repo> <app_branch>
  # /install_app posawesome https://github.com/yrestom/POS-Awesome master && \
  /install_app frappe_s3_attachment https://gitee.com/eanfs32/frappe-attachments-s3.git master && \
  # /install_app metabase_integration https://github.com/pipech/frappe-metabase master && \
  # /install_app bookings https://github.com/franknyarkoh/bookings master && \
  /install_app wiki https://gitee.com/eanfs32/wiki master && \  
  /install_app bench_manager https://gitee.com/eanfs32/bench_manager develop && \
  /install_app erpnext_chinese https://gitee.com/eanfs32/erpnext_chinese develop && \
# Cleanup for production
  /prepare_production

FROM registry.cn-shanghai.aliyuncs.com/xdicloud/erpnext-nginx:${FRAPPE_BRANCH}

COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/
COPY --from=0 /rsync /rsync

# Append list of installed to apps.txt
RUN echo -n "frappe_s3_attachment\nwiki\nbench_manager\nerpnext_chinese" >> /var/www/html/apps.txt
# RUN echo -n "erpnext_chinese" >> /var/www/html/apps.txt

VOLUME [ "/assets" ]

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
